package cn.wizzer.app.crown.modules.models;

import cn.wizzer.app.crown.modules.models.enums.MatchTypeEnum;
import cn.wizzer.app.crown.modules.models.enums.PlayWayEnum;
import cn.wizzer.app.crown.modules.models.enums.SettleStatusEnum;
import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.integration.json4excel.annotation.J4EIgnore;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 订单，单式，
 * 3串1 冠军选项不能放在这里
 */

@Data
@Table("crown_order")
@TableIndexes({@Index(name = "INDEX_CT_AT", fields = {"ctAt"}, unique = false),
        @Index(name = "unique_no", fields = {"no"}, unique = true)})
public class CrownOrder extends BaseModel implements Serializable {


    @Column
    @Name
    @Comment("ID")
    @J4EIgnore
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(uu32 = true)
    private String id;

    @Column("user_id")
    @Comment("用户")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String userId;

    @Column("no")
    @Comment("订单编号")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String no;

    @Column("match_type")
    @Comment("比赛类型")
    @ColDefine(type = ColType.VARCHAR, width = 10)
    private MatchTypeEnum matchType;

    @Column("play_way")
    @Comment("玩法")
    @ColDefine(type = ColType.VARCHAR, width = 10)
    private PlayWayEnum playWay;

    @Column
    @Comment("下注金额")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    private BigDecimal amount;

    @Column
    @Comment("中奖金额")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    private BigDecimal resultAmount;

    /**
     * 订单状态：
     * WAIT_CONFIRM——待确认
     * WAIT_SETTLE——待结算
     * SETTLED——已结算
     * CANCELLED——已取消
     * RESETTLED——重新结算
     */
    @Column
    @Comment("状态->WAIT_CONFIRM:待确认,WAIT_SETTLE:待结算,SETTLED:已结算,CANCELLED:已取消")
    @ColDefine(type = ColType.VARCHAR, width = 12)
    private SettleStatusEnum status;

    @Column
    @Comment("创建时间")
    @PrevInsert(els = @EL("$me.now()"))
    //Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
    private Long ctAt;

    @Column("remark")
    @Comment("备注")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    private String remark;

    @Column
    @Comment("是否已结算")
    @ColDefine(type = ColType.BOOLEAN)
    @Default("0")
    private Boolean counted;

    @Column
    @Comment("结算时间")
    private Long settleAt;



    /**
     * 实际盈亏(resultAmount - amount)。亏损显示负数
     */
    private BigDecimal relAmount;


    /**
     * 可赢金额
     */
    private BigDecimal winAmount;


    /**
     * 订单条目
     */
    private List<CrownOrderDetail> details;

}